function QNew = streamflowARM(QOld, mu, rho, sigma,t)
% A simple autoregressive Markov model
%
% mean flow mu, variance sigma^2 and year to year correlation rho.
%
% Based on booktext: Water Resource Systems Planning and Analysis, D.P.
% Loucks, J.R. Stedinger, D.A. Haith, Chapter 3 there...
%
% Updated so as to produce multiple time series
%
% Tobias Siegfried, 20060519

QNew = mu + rho .* (QOld - mu) + randn(size(QOld,1),size(QOld,2)) .* sigma.* sqrt(1 - rho.^2);
%QNew = mu + sin(2*pi*t/365+pi)*(rho .* (QOld - mu) + randn(size(QOld,1),size(QOld,2)) .* sigma .* sqrt(1 - rho.^2));
%QNew = mu + rho .* (QOld - mu) + sin(2*pi*t/365+pi)*(randn(size(QOld,1),size(QOld,2)) .* sigma .* sqrt(1 - rho.^2));